package com.diaohw.platform.common.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author 刁海文
 * @Remark
 * @since 2023/7/22 14:58
 */
public class ValueUtil {

    /**
     * Reusable Long constant for zero.
     */
    public static final Long LONG_ZERO = 0L;
    /**
     * Reusable Long constant for one.
     */
    public static final Long LONG_ONE = 1L;
    /**
     * Reusable Long constant for minus one.
     */
    public static final Long LONG_MINUS_ONE = -1L;
    /**
     * Reusable Integer constant for zero.
     */
    public static final Integer INTEGER_ZERO = 0;
    /**
     * Reusable Integer constant for one.
     */
    public static final Integer INTEGER_ONE = 1;
    /**
     * Reusable Integer constant for two
     */
    public static final Integer INTEGER_TWO = 2;
    /**
     * Reusable Integer constant for minus one.
     */
    public static final Integer INTEGER_MINUS_ONE = -1;
    /**
     * Reusable Short constant for zero.
     */
    public static final Short SHORT_ZERO = (short) 0;
    /**
     * Reusable Short constant for one.
     */
    public static final Short SHORT_ONE = (short) 1;
    /**
     * Reusable Short constant for minus one.
     */
    public static final Short SHORT_MINUS_ONE = (short) -1;
    /**
     * Reusable Byte constant for zero.
     */
    public static final Byte BYTE_ZERO = (byte) 0;
    /**
     * Reusable Byte constant for one.
     */
    public static final Byte BYTE_ONE = (byte) 1;
    /**
     * Reusable Byte constant for minus one.
     */
    public static final Byte BYTE_MINUS_ONE = (byte) -1;
    /**
     * Reusable Double constant for zero.
     */
    public static final Double DOUBLE_ZERO = 0.0d;
    /**
     * Reusable Double constant for one.
     */
    public static final Double DOUBLE_ONE = 1.0d;
    /**
     * Reusable Double constant for minus one.
     */
    public static final Double DOUBLE_MINUS_ONE = -1.0d;
    /**
     * Reusable Float constant for zero.
     */
    public static final Float FLOAT_ZERO = 0.0f;
    /**
     * Reusable Float constant for one.
     */
    public static final Float FLOAT_ONE = 1.0f;
    /**
     * Reusable Float constant for minus one.
     */
    public static final Float FLOAT_MINUS_ONE = -1.0f;


    public static final String STRING_NULL = null;

    public static final String STRING_EMPTY = "";

    public static final String STRING_ZERO = "0";

    public static final String DEFAULT_TREE_PARENT_ID = STRING_ZERO;

    public static double formatDecimal(double val) {
        return formatDecimal(val, 2);
    }

    public static double formatDecimal(double val, int scale) {
        return new BigDecimal(val).setScale(scale, RoundingMode.HALF_UP).doubleValue();
    }

    public static String formatSize(long size) {
        String[] unit = {" B", " KB", " MB", " GB", " TB", " PB"};
        int index = 0;
        double val = size;
        while (val >= 1024) {
            val = val / 1024.0;
            index++;
        }
        Double decimal = formatDecimal(val);

        return decimal + unit[index];
    }

}
